const jwt = require('jsonwebtoken');
module.exports = {
    //账号密码不为空
    async isnull(ctx, next) {
        const { phone } = ctx.query
        if (!phone || phone.length !== 11) {
            return ctx.body = {
                code: 400,
                msg: '请输入正确手机号码！'
            }
        }
        await next()
    },
    async isslogin(ctx, next) {
        const { token } = ctx.request.header
        if (!token) {
            return ctx.body = {
                code: 401,
                msg: '请先登录！'
            }
        }
        try {
            await jwt.verify(token, 'ximo')
            return await next()
        } catch (error) {
            ctx.status = 401
            return ctx.body = {
                code: 401,
                msg: '登录过期！'
            }
        }
    }
}